﻿namespace Hotel.ModulesTest
{
    using ManagementModule = Hotel.Module.Management;
    using System.Collections.Generic;
    using Hotel.Module.Management;
    using Hotel.Module.Management.Models;
    using NUnit.Framework;

    [TestFixture]
    public class GetCurrentAssignments
    {
        [Test]
        public void GetCurrentAssignmentTestMethod()
        {
            string _initName = "Assigner";

            using (ManagementController m_ManagementController = Hotel.Web.Helpers.ServiceLocator.Instance.GetService(typeof(IManagement)) as ManagementController)
            {
                List<Assignment> _assToDelete = new List<Assignment>();

                foreach (var ass in m_ManagementController.GetAssignments())
                {
                    if (ass.WorkerLogin == _initName)
                    {
                        _assToDelete.Add(ass);
                    }
                }
                foreach (var ass in _assToDelete)
                {
                    m_ManagementController.Storage.Delete(ass);
                }

                m_ManagementController.SaveChanges();
            }

            using (ManagementController m_ManagementController = Hotel.Web.Helpers.ServiceLocator.Instance.GetService(typeof(IManagement)) as ManagementController)
            {
                Hotel.Web.Models.RoomCleaner initCleaner = new Web.Models.RoomCleaner();
                initCleaner.Assignments = new List<Web.Models.Assignment>();

                Assignment initAssignment = new Assignment { WorkerLogin = "Assigner", Description = "Some description", State = AssignmentState.Applied, WorkerType = Assignment.CurrentWorkerType.Cleaners };

                m_ManagementController.Storage.Add(initAssignment);
                m_ManagementController.SaveChanges();

                List<ManagementModule.Models.Assignment> collection = (List<Hotel.Module.Management.Models.Assignment>)m_ManagementController.GetCurrentAssignments("Assigner");

                Assert.AreNotEqual(0, collection.Count);
            }
        }
    }
}
